$(function() {
    //通过父页面，调用点击事件。
    parent.$('.level02 li').eq(1).click();

    //页面预览
    $('#inputCover').on('change', function() {
        let pic = this.files[0];
        let picUrl = URL.createObjectURL(pic);
        $('.article_cover').attr('src', picUrl)
    })

    $.ajax({
        type: 'get',
        url: BigNew.category_list,
        success: function(res) {
            console.log(res);
            if (res.code == 200) {
                let htmlStr = ''; +
                $.each(res.data, function(index, value) {
                    htmlStr += `<option value="${value.id}">${value.name}</option>`
                })
                $('.category').html(htmlStr)
            }
        }
    });

    $('.jebtns').click(function() {
        jeDate("#testico", {
            trigger: false,
            theme: { bgcolor: "#00A680", pnColor: "#00DDAA" },
            format: "YYYY-MM-DD hh:mm:ss",
            zIndex: 20990,
        });
    });

    //富文本事件
    const E = window.wangEditor
    const editor = new E('#div1')
        // 或者 const editor = new E( document.getElementById('div1') )
    editor.create()


    function forData(state) {
        let fd = new FormData(document.querySelector('form'));
        fd.append('state', state);
        fd.append('content', editor.txt.html())
        $.ajax({
            type: 'post',
            url: BigNew.article_publish,
            data: fd,
            contentType: false,
            processData: false,
            success: function(res) {
                console.log(res);
                // alert(res.msg);
                window.location.href = './article_list.html'
            }

        })
    }

    // 发布和存入草稿
    $('.btn-release').click(function(e) {
        e.preventDefault();
        forData('已发布');
    })
    $('.btn-draft').click(function(e) {
        e.preventDefault();
        forData('草稿');
    })
})